package com.store.app.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.store.app.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by liuwy on 2016/2/19.
 */
public class WypRecycleviewAdapter extends RecyclerView.Adapter<WypRecycleviewAdapter.ViewHolder> {


    private List<String> urlList;

    private Context context;

    private LayoutInflater mInflater;

    public WypRecycleviewAdapter(List<String> urlList, Context context) {
        this.context = context;
        mInflater = LayoutInflater.from(context);
        this.urlList = urlList;

    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_stores_service,
                parent, false);
        ViewHolder viewHolder = null;
        viewHolder = new ViewHolder(view);

        viewHolder.ivService = (ImageView) view.findViewById(R.id.stores_service_img);
        viewHolder.tvName = (TextView) view.findViewById(R.id.stores_service_tv);
        viewHolder.tvName.setVisibility(View.GONE);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                MobclickAgent.onEvent(context, "004");
//                Intent intent = new Intent();
//                intent.setClass(context, ServiceActivity.class);
//
//                context.startActivity(intent);
            }
        });
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        String url = urlList.get(position);
        ImageLoader.getInstance().displayImage(url, holder.ivService, options);
    }


    @Override
    public int getItemCount() {
        return urlList.size();
    }

//    @Override
//    public Object getItem(int position) {
//        return serviceList.get(position);
//    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public ViewHolder(View arg0) {
            super(arg0);
        }

        ImageView ivService;
        TextView tvName;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    DisplayImageOptions options = new DisplayImageOptions.Builder()
            .cacheInMemory(true)
            .showImageOnLoading(R.drawable.default_picture_s)
            .showImageOnFail(R.drawable.default_picture_s)
            .showStubImage(R.drawable.default_picture_s)
            .imageScaleType(ImageScaleType.EXACTLY)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .build();
}
